package com.mc.moring.widge.adapter;


import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mc.moring.R;
import com.mc.moring.bean.SingleSelectBean;

import java.util.List;

public class SingleSelectAdapter extends BaseQuickAdapter<SingleSelectBean, BaseViewHolder> {

    SingleSelectListener singleSelectListener;

    public SingleSelectAdapter(@Nullable List<SingleSelectBean> data) {
        super(R.layout.item_single_select, data);
    }

    public interface SingleSelectListener{
        void checked(SingleSelectBean s);
    }

    public void setSingleSelectListener(SingleSelectListener singleSelectListener){
        this.singleSelectListener = singleSelectListener;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, SingleSelectBean s) {
        TextView text = baseViewHolder.getView(R.id.text);
        CheckBox cb_select = baseViewHolder.getView(R.id.cb_select);
        LinearLayout parent = baseViewHolder.getView(R.id.parent);

        cb_select.setChecked(s.isCheck());
        text.setText(s.getText());
        parent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(singleSelectListener!=null){
                    s.setCheck(true);
                    singleSelectListener.checked(s);
                }
            }
        });
    }
}
